<template>
  <div class="modelground">
    <div class="row">
      <div
        class="col-4 animate__animated"
        :class="{
          animate__bounceInLeft: selectedModel === -1,
          animate__zoomOutDown: selectedModel === 0,
          animate__bounceOutLeft: selectedModel === 1 || selectedModel === 2,
        }">
        <div class="btn btn-outline-info" @click="toMatchGround(0)">经典匹配</div>
      </div>
      <div
        class="col-4 animate__animated"
        :class="{
          animate__bounceInUp: selectedModel === -1,
          animate__zoomOutDown: selectedModel === 1,
          animate__bounceOutLeft: selectedModel === 2,
          animate__bounceOutRight: selectedModel === 0,
        }">
        <div class="btn btn-outline-info" @click="toMatchGround(1)">人机对战</div>
      </div>
      <div
        class="col-4 animate__animated"
        :class="{
          animate__bounceInRight: selectedModel === -1,
          animate__zoomOutDown: selectedModel === 2,
          animate__bounceOutRight: selectedModel === 0 || selectedModel === 1,
        }">
        <div class="btn btn-outline-info" @click="toMatchGround(2)">排位模式</div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from "vue";
import { useStore } from "vuex";

export default {
  setup() {
    const store = useStore();

    const selectedModel = ref(-1);

    function toMatchGround(model) {
      // 设置选中不同的模式加载不同的动画
      selectedModel.value = model;

      // 跳转页面
      setTimeout(() => {
        store.commit("updateStatus", "matching");
        selectedModel.value = -1; // 置为初始状态
      }, 300);

      // 更新用户选择的模式
      store.commit("updateSelectModel", model);
    }

    return {
      selectedModel,
      toMatchGround,
    };
  },
};
</script>
<style scoped>
div.modelground {
  width: 80vw;
  height: 80vh;
  margin: 5vh auto;
  background-color: rgba(50, 50, 50, 0.66);
  overflow: hidden;
}

div.row {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}

div.col-4 {
  display: flex;
  justify-content: center;
  align-items: center;
}

div.btn {
  font-size: 28px;
  width: 30vh;
  height: 30vh;
  border-radius: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

div.btn:hover {
  color: white;
  animation: shake 0.5s;
}

@keyframes shake {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

div.btn {
  position: relative;
}

div.btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.2);
  opacity: 0;
  animation: pulse 1s infinite;
}

div.btn:hover::before {
  opacity: 1;
}

@keyframes pulse {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.2;
  }
  100% {
    transform: translate(-50%, -50%) scale(2);
    opacity: 0;
  }
}
</style>
